package com.zhku.meeting.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhku.meeting.entities.Department;
import com.zhku.meeting.entities.Msg;
import com.zhku.meeting.mapper.DepartmentMapper;
import com.zhku.meeting.util.ResultVO;
import com.zhku.meeting.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service
public class LoginService extends ServiceImpl<DepartmentMapper, Department> {
    @Autowired
    private DepartmentMapper departmentMapper;

    public ResultVO<?> login(Map<String , Object> para){
        String name = (String)para.get("username");
        String pwd = (String)para.get("password");
        Department department=new Department();
        department.setDeptNo(name != null ? name.trim() : null);
        department.setDeptPassword(pwd != null ? pwd.trim() : null);
        Department b = departmentMapper.loginMessage(department);
        if (b!=null){
            String token = TokenUtil.sign(b);
            Map<String,Object> map = new HashMap<>();
            map.put("token",token);
            return ResultVO.successData(map);
        }
        return ResultVO.error();
    }
}
